package com.ruoyi.web.controller.trade;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.trade.domain.GridRequest;
import com.ruoyi.trade.domain.TradeBaseGrid;
import com.ruoyi.trade.service.ITradeBaseGridService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 交易基础网格Controller
 * 
 * @author ruoyi
 * @date 2025-09-03
 */
@RestController
@RequestMapping("/trade/tradeBaseGrid")
public class TradeBaseGridController extends BaseController
{
    @Autowired
    private ITradeBaseGridService tradeBaseGridService;

    /**
     * 查询交易基础网格列表
     */
    @PreAuthorize("@ss.hasPermi('trade:tradeBaseGrid:list')")
    @GetMapping("/list")
    public TableDataInfo list(TradeBaseGrid tradeBaseGrid)
    {
        startPage();
        List<TradeBaseGrid> list = tradeBaseGridService.selectTradeBaseGridList(tradeBaseGrid);
        return getDataTable(list);
    }

    /**
     * 导出交易基础网格列表
     */
    @PreAuthorize("@ss.hasPermi('trade:tradeBaseGrid:export')")
    @Log(title = "交易基础网格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TradeBaseGrid tradeBaseGrid)
    {
        List<TradeBaseGrid> list = tradeBaseGridService.selectTradeBaseGridList(tradeBaseGrid);
        ExcelUtil<TradeBaseGrid> util = new ExcelUtil<TradeBaseGrid>(TradeBaseGrid.class);
        util.exportExcel(response, list, "交易基础网格数据");
    }

    /**
     * 获取交易基础网格详细信息
     */
    @PreAuthorize("@ss.hasPermi('trade:tradeBaseGrid:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tradeBaseGridService.selectTradeBaseGridById(id));
    }

    /**
     * 新增交易基础网格
     */
    @PreAuthorize("@ss.hasPermi('trade:tradeBaseGrid:add')")
    @Log(title = "交易基础网格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TradeBaseGrid tradeBaseGrid)
    {
        return toAjax(tradeBaseGridService.insertTradeBaseGrid(tradeBaseGrid));
    }

    /**
     * 修改交易基础网格
     */
    @PreAuthorize("@ss.hasPermi('trade:tradeBaseGrid:edit')")
    @Log(title = "交易基础网格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TradeBaseGrid tradeBaseGrid)
    {
        return toAjax(tradeBaseGridService.updateTradeBaseGrid(tradeBaseGrid));
    }

    /**
     * 删除交易基础网格
     */
    @PreAuthorize("@ss.hasPermi('trade:tradeBaseGrid:remove')")
    @Log(title = "交易基础网格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tradeBaseGridService.deleteTradeBaseGridByIds(ids));
    }

    /**
     * 生成网格数据
     */
    @PreAuthorize("@ss.hasPermi('trade:tradeBaseGrid:add')")
    @Log(title = "网格生成", businessType = BusinessType.INSERT)
    @PostMapping("/generate")
    public AjaxResult generate(@RequestBody GridRequest gridRequest)
    {
        return toAjax(tradeBaseGridService.generateGrid(gridRequest));
    }
}
